/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * pPartnerChooser.java
 *
 * Created on Feb 22, 2011, 10:35:48 AM
 */

package com.fa.supporters;

import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author tatung
 */
public class pPartnerChooser extends javax.swing.JPanel {

    /** Creates new form pPartnerChooser */
    private int selectedID;
    private String PartnerName;
    private int idPartner;
    private PartnerChooserMode mode = PartnerChooserMode.Adding;
    
    public pPartnerChooser() {
        initComponents();
        //this.PartnerTable.setModel(DbConnector.getPartnersTable().getModel());
        this.PartnerTable.setModel(DbConnector.getPartnersTableModel());
        ListSelectionModel rowSelectionModel = this.PartnerTable.getSelectionModel();
        rowSelectionModel.addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent lse) {
                int index = ((ListSelectionModel)lse.getSource()).getMinSelectionIndex();
                selectedID =  (Integer)(PartnerTable.getValueAt(index, 0));
                PartnerName = (String)(PartnerTable.getValueAt(index, 1));
            }
        });
    }

    public void setMode(PartnerChooserMode mode){
        this.mode = mode;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        PartnerTable = new javax.swing.JTable();

        PartnerTable.setAutoCreateRowSorter(true);
        PartnerTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(PartnerTable);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 448, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 325, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    public int getSelectedID(){
        return selectedID;
    }

    public String getPartnerName(){
        return PartnerName;
    }

    public int getIdPartner() {
        return idPartner;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable PartnerTable;
    private javax.swing.JScrollPane jScrollPane2;
    // End of variables declaration//GEN-END:variables

}
